define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'yl/member/index' + location.search,
                    add_url: 'yl/member/add',
                    edit_url: 'yl/member/edit',
                    del_url: 'yl/member/del',
                    multi_url: 'yl/member/multi',
                    import_url: 'yl/member/import',
                    table: 'yl_member',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user', title: __('User'), operate: 'LIKE'},
                        //{field: 'email', title: __('Email'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'integral', title: __('Integral')},
                        //{field: 'phone_ex', title: __('Phone_ex'), operate: 'LIKE'},
                        //{field: 'phone', title: __('Phone'), operate: 'LIKE'},
                        //{field: 'password', title: __('Password'), operate: 'LIKE'},
                        //{field: 'salt', title: __('Salt'), operate: 'LIKE'},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'login_time', title: __('Login_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'ip', title: __('Ip'), operate: 'LIKE'},
                        //{field: 'price', title: __('Price'), operate:'BETWEEN'},
                        //{field: 'code', title: __('Code'), operate: 'LIKE'},
                        //{field: 'token', title: __('Token'), operate: 'LIKE'},
                        //{field: 'share_id', title: __('Share_id')},
                        //{field: 'level', title: __('Level')},
                        //{field: 'locking_level', title: __('Locking_level')},
                        //{field: 'security_password', title: __('Security_password'), operate: 'LIKE'},
                        //{field: 'frozen_price', title: __('Frozen_price'), operate:'BETWEEN'},
                        //{field: 'nick_name', title: __('Nick_name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        //{field: 'avatar', title: __('Avatar'), operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image},
                        //{field: 'birthday', title: __('Birthday'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        //{field: 'sex', title: __('Sex'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        //{field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"0":__('Status 0'),"2":__('Status 2')}, formatter: Table.api.formatter.status},
                        //{field: 'auth_id', title: __('Auth_id'), searchList: {"1":__('Auth_id 1'),"0":__('Auth_id 0')}, formatter: Table.api.formatter.normal},
                        //{field: 'is_frozen', title: __('Is_frozen'), searchList: {"1":__('Is_frozen 1'),"0":__('Is_frozen 0')}, formatter: Table.api.formatter.normal},
                        {field: 'operate',cellStyle: {css: {
                                    "max-width": "300px",
                                }},title: __('Operate'), buttons:[
                                {
                                    name:'list',
                                    text:__("重置密码"),
                                    title:__("重置密码"),
                                    classname:'btn btn-xs btn-warning btn-dialog test_css',
                                    icon:'',
                                    url:'yl/member/pass/type/1',
                                },
                                // {
                                //     name:'list',
                                //     text:__("修改上级"),
                                //     title:__("修改上级"),
                                //     classname:'btn btn-xs btn-warning btn-dialog test_css',
                                //     icon:'',
                                //     url:'yl/member/share/type/2',
                                // }
                            ],table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        pass: function () {
            Controller.api.bindevent();
        },
        share: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
